Skip to content

fix(dialect): make extend_sqlglot idempotent - #5921

Open
Sanjays2402 wants to merge 1 commit into
SQLMesh:mainfrom
Sanjays2402:fix/extend-sqlglot-idempotent
Open

fix(dialect): make extend_sqlglot idempotent#5921
Sanjays2402 wants to merge 1 commit into
SQLMesh:mainfrom
Sanjays2402:fix/extend-sqlglot-idempotent

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #5908

Description

_override saved whatever was currently installed under _<name>, so a second extend_sqlglot() call saved the override itself as the "original". The wrapper then called itself and every subsequent type/CAST parse raised RecursionError, with sqlglot's original method lost. This is reachable without calling it twice on purpose: extend_sqlglot() is the first statement of sqlmesh/__init__.py, so if anything later in that import cascade raises, the package is evicted from sys.modules while the patched globals survive, and the retry re-applies the patch.

_override now returns early when the override is already installed.

Test Plan

Added tests/core/test_dialect.py::test_extend_sqlglot_is_idempotent, which fails with RecursionError without the fix and passes with it. tests/core/test_dialect.py is green (160 passed).

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

_override saved whatever was currently installed under _<name>, so a second
extend_sqlglot() call saved the override itself as the original. The wrapper
then called itself and every subsequent type/CAST parse raised RecursionError,
with sqlglot's original method lost.

_override now returns early when the override is already installed.

Adds tests/core/test_dialect.py::test_extend_sqlglot_is_idempotent, which fails
with RecursionError without the fix.

Signed-off-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com>

@StuffbyYuki StuffbyYuki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sanjays2402 Thanks for the PR! Here are a few things (not blockers):

  • Also guard generator.UNWRAPPED_INTERVAL_VALUES (still appends every call; TRANSFORMS / WITH_SEPARATED_COMMENTS already have membership guards — called out in #5908).
  • Optional assert that a second call doesn’t grow UNWRAPPED_INTERVAL_VALUES (or that __parse_types still points at sqlglot’s original).

Merge ready once ci tests pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extend_sqlglot() is not idempotent — a second call makes Parser._parse_types recurse infinitely (RecursionError)

2 participants